package com.sky.controller.admin;


import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.pojo.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类管理
 */
@RestController
@RequestMapping("/admin/category")
@Api(tags = "分类相关接口")
@Slf4j
public class CategoryController {
    @Autowired
    CategoryService categoryService;
   @PostMapping
   @ApiOperation("新增分类")
    public Result<String>  AddCuisine(@RequestBody CategoryDTO categoryDTO){

       log.info("新增分类:{}",categoryDTO);


       categoryService.AddCuisine(categoryDTO);




      return  Result.success();

}


   @GetMapping("/list")
   @ApiOperation("根据类型查询分类")
    public  Result <List<Category>> list( Integer type){

        List<Category> list = categoryService.list(type);



       return   Result.success(list);
    }



    @GetMapping("/page")
    @ApiOperation("分页查询分类")
    public  Result <PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){

     PageResult pageResult = categoryService.page(categoryPageQueryDTO);

       return  Result.success(pageResult);
    }

    @PostMapping("/status/{status}")
    @ApiOperation("分类启用禁用")
    public  Result<String> operate (Long id ,@PathVariable("status") Integer status){

       return  categoryService. operate(id,status);


    }

    @PutMapping
    @ApiOperation("修改分类")
    public  Result<String> update(@RequestBody CategoryDTO categoryDTO){

       categoryService.update(categoryDTO);

        return Result.success();
    }


   @DeleteMapping
   @ApiOperation("删除分类")
    public  Result<String> DeleteId(Long id){
       categoryService. DeleteId(id);

       return Result.success();
    }




}
